package com.ruoyi.information.controller.pc;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.information.domain.pc.ServiceCenter;
import com.ruoyi.information.service.pc.IServiceCenterService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;

/**
 * 体系分类Controller
 *
 * @author ruoyi
 * @date 2023-05-17
 */
@RestController
@RequestMapping("/center")
public class ServiceCenterController extends BaseController
{
    @Autowired
    private IServiceCenterService serviceCenterService;

    /**
     * 查询体系分类列表
     */
    @GetMapping("/list")
    public AjaxResult list(ServiceCenter serviceCenter)
    {
//        if (serviceCenter.getParentId()==null){
//            serviceCenter.setParentId(0L);
//        }
        List<ServiceCenter> list = serviceCenterService.selectServiceCenterList(serviceCenter);
        return success(list);
    }

    /**
     * 导出体系分类列表
     */
    @PostMapping("/export")
    public void export(HttpServletResponse response, ServiceCenter serviceCenter)
    {
        List<ServiceCenter> list = serviceCenterService.selectServiceCenterList(serviceCenter);
        ExcelUtil<ServiceCenter> util = new ExcelUtil<ServiceCenter>(ServiceCenter.class);
        util.exportExcel(response, list, "体系分类数据");
    }

    /**
     * 获取体系分类详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(serviceCenterService.selectServiceCenterById(id));
    }

    /**
     * 新增体系分类
     */
    @PostMapping
    public AjaxResult add(@RequestBody ServiceCenter serviceCenter)
    {
        return toAjax(serviceCenterService.insertServiceCenter(serviceCenter));
    }

    /**
     * 修改体系分类
     */
    @PutMapping
    public AjaxResult edit(@RequestBody ServiceCenter serviceCenter)
    {
        return toAjax(serviceCenterService.updateServiceCenter(serviceCenter));
    }

    /**
     * 删除体系分类
     */
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(serviceCenterService.deleteServiceCenterByIds(ids));
    }
}
